/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFFiliais.java
 *
 * Created on 18/09/2012, 19:30:34
 */

package ecommercial;

import ecommercial.Classes.ClassConecta;
import ecommercial.Classes.Filiais;
import ecommercial.Classes.Funcoes;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Luciano Carrafa Benfica
 */
public class jFFiliais extends javax.swing.JDialog {

    /** Creates new form jFFiliais */
    public jFFiliais() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        buscarjButton = new javax.swing.JButton();
        novojButton = new javax.swing.JButton();
        editarjButton = new javax.swing.JButton();
        salvarjButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        alterarjButton = new javax.swing.JButton();
        excluirjButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        sairjButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        gradeFiliaisjTable = new javax.swing.JTable();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        situacaojComboBox = new javax.swing.JComboBox();
        data_aberturajFormattedTextField = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        permiteCreditoClientejComboBox = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        permiteBaixaCartaojComboBox = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        mesmaSeqOrdensjComboBox = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        insc_municipaljTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        insc_suframajTextField = new javax.swing.JTextField();
        inscriçãoEstadualjTextField = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        regimeTributariojTextField = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        operacao_simples_nacionaljTextField = new javax.swing.JTextField();
        carenciajTextField = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        aliqMensaljTextField = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        aliqMultajTextField = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        obsjTextArea = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ecommercial.EcommercialApp.class).getContext().getResourceMap(jFFiliais.class);
        jToolBar1.setBackground(resourceMap.getColor("jToolBar1.background")); // NOI18N
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        buscarjButton.setBackground(resourceMap.getColor("buscarjButton.background")); // NOI18N
        buscarjButton.setIcon(resourceMap.getIcon("buscarjButton.icon")); // NOI18N
        buscarjButton.setText(resourceMap.getString("buscarjButton.text")); // NOI18N
        buscarjButton.setFocusable(false);
        buscarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buscarjButton.setName("buscarjButton"); // NOI18N
        buscarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buscarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(buscarjButton);

        novojButton.setBackground(resourceMap.getColor("novojButton.background")); // NOI18N
        novojButton.setIcon(resourceMap.getIcon("novojButton.icon")); // NOI18N
        novojButton.setText(resourceMap.getString("novojButton.text")); // NOI18N
        novojButton.setFocusable(false);
        novojButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        novojButton.setName("novojButton"); // NOI18N
        novojButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        novojButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novojButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(novojButton);

        editarjButton.setBackground(resourceMap.getColor("editarjButton.background")); // NOI18N
        editarjButton.setIcon(resourceMap.getIcon("editarjButton.icon")); // NOI18N
        editarjButton.setText(resourceMap.getString("editarjButton.text")); // NOI18N
        editarjButton.setFocusable(false);
        editarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editarjButton.setName("editarjButton"); // NOI18N
        editarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(editarjButton);

        salvarjButton.setBackground(resourceMap.getColor("salvarjButton.background")); // NOI18N
        salvarjButton.setIcon(resourceMap.getIcon("salvarjButton.icon")); // NOI18N
        salvarjButton.setText(resourceMap.getString("salvarjButton.text")); // NOI18N
        salvarjButton.setFocusable(false);
        salvarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        salvarjButton.setName("salvarjButton"); // NOI18N
        salvarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        salvarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(salvarjButton);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jToolBar1.add(jSeparator1);

        alterarjButton.setBackground(resourceMap.getColor("alterarjButton.background")); // NOI18N
        alterarjButton.setIcon(resourceMap.getIcon("alterarjButton.icon")); // NOI18N
        alterarjButton.setText(resourceMap.getString("alterarjButton.text")); // NOI18N
        alterarjButton.setFocusable(false);
        alterarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        alterarjButton.setName("alterarjButton"); // NOI18N
        alterarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        alterarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                alterarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(alterarjButton);

        excluirjButton.setBackground(resourceMap.getColor("excluirjButton.background")); // NOI18N
        excluirjButton.setIcon(resourceMap.getIcon("excluirjButton.icon")); // NOI18N
        excluirjButton.setText(resourceMap.getString("excluirjButton.text")); // NOI18N
        excluirjButton.setFocusable(false);
        excluirjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        excluirjButton.setName("excluirjButton"); // NOI18N
        excluirjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        excluirjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(excluirjButton);

        jSeparator2.setName("jSeparator2"); // NOI18N
        jToolBar1.add(jSeparator2);

        sairjButton.setBackground(resourceMap.getColor("sairjButton.background")); // NOI18N
        sairjButton.setIcon(resourceMap.getIcon("sairjButton.icon")); // NOI18N
        sairjButton.setText(resourceMap.getString("sairjButton.text")); // NOI18N
        sairjButton.setFocusable(false);
        sairjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sairjButton.setName("sairjButton"); // NOI18N
        sairjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sairjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(sairjButton);

        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jPanel2.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel2.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel2.border.titleColor"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        gradeFiliaisjTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "#Id", "Situação", "Crédito Cliente", "Baixa Cartão", "Usar Mesm. Ordem", "Data Abertura"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gradeFiliaisjTable.setName("gradeFiliaisjTable"); // NOI18N
        gradeFiliaisjTable.getTableHeader().setReorderingAllowed(false);
        gradeFiliaisjTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gradeFiliaisjTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(gradeFiliaisjTable);
        gradeFiliaisjTable.getColumnModel().getColumn(0).setResizable(false);
        gradeFiliaisjTable.getColumnModel().getColumn(0).setPreferredWidth(60);
        gradeFiliaisjTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("gradeFiliaisjTable.columnModel.title0")); // NOI18N
        gradeFiliaisjTable.getColumnModel().getColumn(1).setResizable(false);
        gradeFiliaisjTable.getColumnModel().getColumn(1).setPreferredWidth(100);
        gradeFiliaisjTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("gradeFiliaisjTable.columnModel.title1")); // NOI18N
        gradeFiliaisjTable.getColumnModel().getColumn(2).setResizable(false);
        gradeFiliaisjTable.getColumnModel().getColumn(2).setPreferredWidth(100);
        gradeFiliaisjTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("gradeFiliaisjTable.columnModel.title2")); // NOI18N
        gradeFiliaisjTable.getColumnModel().getColumn(3).setResizable(false);
        gradeFiliaisjTable.getColumnModel().getColumn(3).setPreferredWidth(100);
        gradeFiliaisjTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("gradeFiliaisjTable.columnModel.title3")); // NOI18N
        gradeFiliaisjTable.getColumnModel().getColumn(4).setResizable(false);
        gradeFiliaisjTable.getColumnModel().getColumn(4).setPreferredWidth(100);
        gradeFiliaisjTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("gradeFiliaisjTable.columnModel.title4")); // NOI18N
        gradeFiliaisjTable.getColumnModel().getColumn(5).setResizable(false);
        gradeFiliaisjTable.getColumnModel().getColumn(5).setPreferredWidth(100);
        gradeFiliaisjTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("gradeFiliaisjTable.columnModel.title5")); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 715, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.setForeground(resourceMap.getColor("jTabbedPane1.foreground")); // NOI18N
        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jPanel4.setBackground(resourceMap.getColor("jPanel4.background")); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        situacaojComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ATIVO", "INATIVO" }));
        situacaojComboBox.setName("situacaojComboBox"); // NOI18N

        try {
            data_aberturajFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        data_aberturajFormattedTextField.setName("data_aberturajFormattedTextField"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        permiteCreditoClientejComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "...", "SIM", "NÃO" }));
        permiteCreditoClientejComboBox.setToolTipText(resourceMap.getString("permiteCreditoClientejComboBox.toolTipText")); // NOI18N
        permiteCreditoClientejComboBox.setName("permiteCreditoClientejComboBox"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        permiteBaixaCartaojComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "...", "SIM", "NÃO" }));
        permiteBaixaCartaojComboBox.setToolTipText(resourceMap.getString("permiteBaixaCartaojComboBox.toolTipText")); // NOI18N
        permiteBaixaCartaojComboBox.setName("permiteBaixaCartaojComboBox"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        mesmaSeqOrdensjComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "...", "SIM", "NÃO" }));
        mesmaSeqOrdensjComboBox.setToolTipText(resourceMap.getString("mesmaSeqOrdensjComboBox.toolTipText")); // NOI18N
        mesmaSeqOrdensjComboBox.setName("mesmaSeqOrdensjComboBox"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        insc_municipaljTextField.setText(resourceMap.getString("insc_municipaljTextField.text")); // NOI18N
        insc_municipaljTextField.setName("insc_municipaljTextField"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        insc_suframajTextField.setText(resourceMap.getString("insc_suframajTextField.text")); // NOI18N
        insc_suframajTextField.setName("insc_suframajTextField"); // NOI18N

        inscriçãoEstadualjTextField.setText(resourceMap.getString("inscriçãoEstadualjTextField.text")); // NOI18N
        inscriçãoEstadualjTextField.setName("inscriçãoEstadualjTextField"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        regimeTributariojTextField.setText(resourceMap.getString("regimeTributariojTextField.text")); // NOI18N
        regimeTributariojTextField.setName("regimeTributariojTextField"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        operacao_simples_nacionaljTextField.setText(resourceMap.getString("operacao_simples_nacionaljTextField.text")); // NOI18N
        operacao_simples_nacionaljTextField.setName("operacao_simples_nacionaljTextField"); // NOI18N

        carenciajTextField.setText(resourceMap.getString("carenciajTextField.text")); // NOI18N
        carenciajTextField.setName("carenciajTextField"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        aliqMensaljTextField.setText(resourceMap.getString("aliqMensaljTextField.text")); // NOI18N
        aliqMensaljTextField.setName("aliqMensaljTextField"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        aliqMultajTextField.setText(resourceMap.getString("aliqMultajTextField.text")); // NOI18N
        aliqMultajTextField.setName("aliqMultajTextField"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(operacao_simples_nacionaljTextField, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(insc_suframajTextField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(situacaojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel1))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel2)
                                            .addComponent(data_aberturajFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addComponent(jLabel7))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel3)
                                            .addComponent(permiteCreditoClientejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel4)
                                            .addComponent(permiteBaixaCartaojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(inscriçãoEstadualjTextField))
                                .addComponent(jLabel8))))
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(mesmaSeqOrdensjComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(insc_municipaljTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                            .addComponent(jLabel6)))
                    .addComponent(regimeTributariojTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(66, 66, 66))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(carenciajTextField)
                                .addGap(18, 18, 18)))
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(aliqMensaljTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                                .addGap(18, 18, 18))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addGap(39, 39, 39)))
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(aliqMultajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {data_aberturajFormattedTextField, situacaojComboBox});

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {permiteBaixaCartaojComboBox, permiteCreditoClientejComboBox});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(situacaojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(data_aberturajFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(permiteCreditoClientejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(permiteBaixaCartaojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mesmaSeqOrdensjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(insc_municipaljTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(insc_suframajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(inscriçãoEstadualjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(regimeTributariojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(operacao_simples_nacionaljTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(aliqMensaljTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(aliqMultajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carenciajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N

        jPanel6.setBackground(resourceMap.getColor("jPanel6.background")); // NOI18N
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel6.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel6.border.titleColor"))); // NOI18N
        jPanel6.setName("jPanel6"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        obsjTextArea.setColumns(20);
        obsjTextArea.setRows(5);
        obsjTextArea.setName("obsjTextArea"); // NOI18N
        obsjTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                obsjTextAreaKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(obsjTextArea);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 710, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel5.TabConstraints.tabTitle"), jPanel5); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 747, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 767, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public ClassConecta conexao = new ClassConecta();

    public int cod_filiais;


    public void getGrandeFiliais() throws ParseException{
       //Consultar Filiais
        Filiais oFilial = new Filiais();

        ResultSet resultSet = null;

        String[] colunasTabela = new String[]{"Id#", "Situação", "Crédito Cliente", "Baixa Cartão", "Usar Mesm. Ordem", "Data Abertura"};
        DefaultTableModel modeloTabela = new DefaultTableModel(null, colunasTabela) {

            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };
        gradeFiliaisjTable.setModel(modeloTabela);
        gradeFiliaisjTable.getColumnModel().getColumn(0).setPreferredWidth(60);
        gradeFiliaisjTable.getColumnModel().getColumn(1).setPreferredWidth(100);
        gradeFiliaisjTable.getColumnModel().getColumn(2).setPreferredWidth(100);
        gradeFiliaisjTable.getColumnModel().getColumn(3).setPreferredWidth(100);
        gradeFiliaisjTable.getColumnModel().getColumn(4).setPreferredWidth(100);
        gradeFiliaisjTable.getColumnModel().getColumn(5).setPreferredWidth(100);




try {
            oFilial.setCod_pessoa(cod_filiais);

            resultSet = oFilial.getConsultar();

            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Filiais.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {


                //Formatar data
                Date abertura = resultSet.getDate("DAT_ABERTURA");

                String dat_abertura = null;
                if (abertura != null){
                SimpleDateFormat formatoDataLanc = new SimpleDateFormat("dd/MM/yyyy");
                dat_abertura = formatoDataLanc.format(abertura);
                }else{
                dat_abertura = "";
                }
                //Fim formatação


                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("COD_PESSOA")),
                    resultSet.getString("SITUACAO"),
                    resultSet.getString("PERMITE_CREDITO_CLIENTE") ,
                    resultSet.getString("PERMITE_BAIXA_CARTAO"),
                    resultSet.getString("USAR_MESMA_SEQ_ORDEM"),
                    dat_abertura
                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(Filiais.class.getName()).log(Level.SEVERE, null, ex);
        }

           }


    public void getFieldFiliais(int cod_filiais) throws ParseException{

        Filiais oFiliais = new Filiais();
        ResultSet rs = null;
        oFiliais.setCod_pessoa(cod_filiais);

        try {
            rs = oFiliais.getConsultar();
            rs.next();

            //Pegar campos
            situacaojComboBox.setSelectedItem(rs.getString("SITUACAO"));
            data_aberturajFormattedTextField.setValue(Funcoes.getDataFormat(rs.getDate("DAT_ABERTURA")));
            permiteCreditoClientejComboBox.setSelectedItem(rs.getString("PERMITE_CREDITO_CLIENTE"));
            permiteBaixaCartaojComboBox.setSelectedItem(rs.getString("PERMITE_BAIXA_CARTAO"));
            mesmaSeqOrdensjComboBox.setSelectedItem(rs.getString("USAR_MESMA_SEQ_ORDEM"));
            obsjTextArea.setText(rs.getString("OBS"));
            insc_municipaljTextField.setText(rs.getString("INSC_MUNICIPAL"));
            insc_suframajTextField.setText(rs.getString("INSC_SUFRAMA"));
            inscriçãoEstadualjTextField.setText(rs.getString("INSC_ESTADUAL"));
            regimeTributariojTextField.setText(rs.getString("REGIME_TRIBUTARIO"));
            operacao_simples_nacionaljTextField.setText(rs.getString("OPERACAO_SIMPLES_NACIONAL"));
            carenciajTextField.setText(rs.getString("DIAS_CARENCIA"));
            aliqMensaljTextField.setText(rs.getString("ALIQ_JUROS_MENSAL"));
            aliqMultajTextField.setText(rs.getString("ALIQ_MULTA"));
            

        } catch (SQLException ex) {
            Logger.getLogger(Filiais.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:

        ClassConecta.conecta();

        salvarjButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        novojButton.setEnabled(true);

        buscarjButtonActionPerformed(null);

    }//GEN-LAST:event_formWindowOpened

    private void sairjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairjButtonActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_sairjButtonActionPerformed

    private void novojButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novojButtonActionPerformed
        // TODO add your handling code here:

        novojButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        buscarjButton.setEnabled(true);
        salvarjButton.setEnabled(true);

        situacaojComboBox.setSelectedItem("ATIVO");
        data_aberturajFormattedTextField.setText("");
        permiteCreditoClientejComboBox.setSelectedItem("...");
        permiteBaixaCartaojComboBox.setSelectedItem("...");
        mesmaSeqOrdensjComboBox.setSelectedItem("...");
        insc_municipaljTextField.setText("");
        insc_suframajTextField.setText("");
        inscriçãoEstadualjTextField.setText("");
        regimeTributariojTextField.setText("");
        operacao_simples_nacionaljTextField.setText("");
        carenciajTextField.setText("");
        aliqMensaljTextField.setText("");
        aliqMultajTextField.setText("");
        obsjTextArea.setText("");
    }//GEN-LAST:event_novojButtonActionPerformed

    private void salvarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarjButtonActionPerformed
        // TODO add your handling code here:
            salvarjButton.setEnabled(false);
            alterarjButton.setEnabled(false);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);
            editarjButton.setEnabled(true);

            Filiais oFilial = new Filiais();

            if(data_aberturajFormattedTextField.getText().equals("  /  /    ")){

                JOptionPane.showMessageDialog(null, "Campo DATA ABERTURA esta vazio. Escolha uma opção.", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else if (permiteCreditoClientejComboBox.getSelectedItem().equals("...")){

                JOptionPane.showMessageDialog(null, "O campo CRÉDITO CLIENTE está vazio. Escolha uma opção.", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else if (permiteBaixaCartaojComboBox.getSelectedItem().equals("...")){

                JOptionPane.showMessageDialog(null, "Campo BAIXA CARTÃO esta vazio. Escolha uma opção.", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else if (mesmaSeqOrdensjComboBox.getSelectedItem().equals("...")){

                JOptionPane.showMessageDialog(null, "Campo MESMA SEQ. DE ORDEM esta vazio. Escolha uma opção.", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else{
            try {

                oFilial.setCod_pessoa(cod_filiais);

                oFilial.setSituacao(situacaojComboBox.getSelectedItem().toString());
                oFilial.setDat_abertura(Funcoes.getDataFormatBR(data_aberturajFormattedTextField.getText()));
                oFilial.setPermite_credito_cliente(permiteCreditoClientejComboBox.getSelectedItem().toString());
                oFilial.setPermite_baixa_cartao(permiteBaixaCartaojComboBox.getSelectedItem().toString());
                oFilial.setUsar_mesma_ordem(mesmaSeqOrdensjComboBox.getSelectedItem().toString());
                oFilial.setInsc_municipal(insc_municipaljTextField.getText().trim().toUpperCase());
                oFilial.setInsc_suframa(insc_suframajTextField.getText().trim().toUpperCase());
                oFilial.setInsc_estadual(inscriçãoEstadualjTextField.getText().trim().toUpperCase());
                oFilial.setRegime_tributario(regimeTributariojTextField.getText().trim().toUpperCase());
                oFilial.setOperacao_simples_nacional(operacao_simples_nacionaljTextField.getText().trim().toUpperCase());
                oFilial.setDias_carencia(Integer.parseInt(carenciajTextField.getText()));
                oFilial.setAliq_juros_mensal(Float.parseFloat(aliqMensaljTextField.getText()));
                oFilial.setAliq_multa(Float.parseFloat(aliqMultajTextField.getText()));
                oFilial.setObs(obsjTextArea.getText().trim());
                oFilial.setCadastrar();

            } catch (ParseException ex) {
                Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                ClassConecta.con.commit();
                ClassConecta.con.setAutoCommit(true);
            } catch (SQLException ex) {
                Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                getGrandeFiliais();
            } catch (ParseException ex) {
                Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
            }



            }


    }//GEN-LAST:event_salvarjButtonActionPerformed

    private void buscarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            getGrandeFiliais();
        } catch (ParseException ex) {
            Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buscarjButtonActionPerformed

    private void gradeFiliaisjTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gradeFiliaisjTableMouseClicked
        // TODO add your handling code here:
        editarjButton.setEnabled(true);
            cod_filiais = Integer.parseInt(gradeFiliaisjTable.getValueAt(gradeFiliaisjTable.getSelectedRow(), 0).toString());
            if (cod_filiais == 0) {
                return;
            }
        try {
            getFieldFiliais(cod_filiais);
        } catch (ParseException ex) {
            Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_gradeFiliaisjTableMouseClicked

    private void editarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarjButtonActionPerformed
        // TODO add your handling code here:
            novojButton.setEnabled(false);
            salvarjButton.setEnabled(false);
            editarjButton.setEnabled(false);
            alterarjButton.setEnabled(true);
            excluirjButton.setEnabled(true);
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_editarjButtonActionPerformed

    private void alterarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alterarjButtonActionPerformed
        // TODO add your handling code here:
            alterarjButton.setEnabled(false);
            editarjButton.setEnabled(true);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);

            Filiais oFilial = new Filiais();

            if(data_aberturajFormattedTextField.getText().equals("  /  /    ")){

                JOptionPane.showMessageDialog(null, "Campo DATA ABERTURA esta vazio. Escolha uma opção.", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else if (permiteCreditoClientejComboBox.getSelectedItem().equals("...")){

                JOptionPane.showMessageDialog(null, "O campo CRÉDITO CLIENTE está vazio. Escolha uma opção.", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else if (permiteBaixaCartaojComboBox.getSelectedItem().equals("...")){

                JOptionPane.showMessageDialog(null, "Campo BAIXA CARTÃO esta vazio. Escolha uma opção.", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else if (mesmaSeqOrdensjComboBox.getSelectedItem().equals("...")){

                JOptionPane.showMessageDialog(null, "Campo MESMA SEQ. DE ORDEM esta vazio. Escolha uma opção.", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else{
            try {
                oFilial.setCod_pessoa(cod_filiais);

                oFilial.setSituacao(situacaojComboBox.getSelectedItem().toString());
                oFilial.setDat_abertura(Funcoes.getDataFormatBR(data_aberturajFormattedTextField.getText()));
                oFilial.setPermite_credito_cliente(permiteCreditoClientejComboBox.getSelectedItem().toString());
                oFilial.setPermite_baixa_cartao(permiteBaixaCartaojComboBox.getSelectedItem().toString());
                oFilial.setUsar_mesma_ordem(mesmaSeqOrdensjComboBox.getSelectedItem().toString());
                oFilial.setInsc_municipal(insc_municipaljTextField.getText().trim().toUpperCase());
                oFilial.setInsc_suframa(insc_suframajTextField.getText().trim().toUpperCase());
                oFilial.setInsc_estadual(inscriçãoEstadualjTextField.getText().trim().toUpperCase());
                oFilial.setRegime_tributario(regimeTributariojTextField.getText().trim().toUpperCase());
                oFilial.setOperacao_simples_nacional(operacao_simples_nacionaljTextField.getText().trim().toUpperCase());
                oFilial.setDias_carencia(Integer.parseInt(carenciajTextField.getText()));
                oFilial.setAliq_juros_mensal(Float.parseFloat(aliqMensaljTextField.getText()));
                oFilial.setAliq_multa(Float.parseFloat(aliqMultajTextField.getText()));
                oFilial.setObs(obsjTextArea.getText().trim());
                oFilial.setAlterar(conexao);

            } catch (ParseException ex) {
                Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                ClassConecta.con.commit();
                ClassConecta.con.setAutoCommit(true);
            } catch (SQLException ex) {
                Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                getGrandeFiliais();
            } catch (ParseException ex) {
                Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_alterarjButtonActionPerformed

    private void excluirjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirjButtonActionPerformed
        // TODO add your handling code here:
        Object[] options = {"Sim", "Não"};
        int sd =
                JOptionPane.showOptionDialog(null, "Deseja realmente EXCLUIR esse registro?", "Confirmação!", JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[0]);

        if (sd != 0) {
            return;
        }
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(true);
        excluirjButton.setEnabled(false);
        novojButton.setEnabled(true);

        Filiais oFilial = new Filiais();
        oFilial.setCod_pessoa(cod_filiais);
        oFilial.setExcluir(conexao);
        try {
            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);
        } catch (SQLException ex) {
            Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            getGrandeFiliais();
        } catch (ParseException ex) {
            Logger.getLogger(jFFiliais.class.getName()).log(Level.SEVERE, null, ex);
        }
        situacaojComboBox.setSelectedItem("ATIVO");
        data_aberturajFormattedTextField.setText("");
        permiteCreditoClientejComboBox.setSelectedItem("...");
        permiteBaixaCartaojComboBox.setSelectedItem("...");
        mesmaSeqOrdensjComboBox.setSelectedItem("...");
        insc_municipaljTextField.setText("");
        insc_suframajTextField.setText("");
        inscriçãoEstadualjTextField.setText("");
        regimeTributariojTextField.setText("");
        operacao_simples_nacionaljTextField.setText("");
        carenciajTextField.setText("");
        aliqMensaljTextField.setText("");
        aliqMultajTextField.setText("");
        obsjTextArea.setText("");
    }//GEN-LAST:event_excluirjButtonActionPerformed

    private void obsjTextAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_obsjTextAreaKeyTyped
        // TODO add your handling code here:
        obsjTextArea.setLineWrap(true);
        obsjTextArea.setWrapStyleWord(true);
    }//GEN-LAST:event_obsjTextAreaKeyTyped

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFFiliais().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField aliqMensaljTextField;
    private javax.swing.JTextField aliqMultajTextField;
    private javax.swing.JButton alterarjButton;
    private javax.swing.JButton buscarjButton;
    private javax.swing.JTextField carenciajTextField;
    private javax.swing.JFormattedTextField data_aberturajFormattedTextField;
    private javax.swing.JButton editarjButton;
    private javax.swing.JButton excluirjButton;
    private javax.swing.JTable gradeFiliaisjTable;
    private javax.swing.JTextField insc_municipaljTextField;
    private javax.swing.JTextField insc_suframajTextField;
    private javax.swing.JTextField inscriçãoEstadualjTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JComboBox mesmaSeqOrdensjComboBox;
    private javax.swing.JButton novojButton;
    private javax.swing.JTextArea obsjTextArea;
    private javax.swing.JTextField operacao_simples_nacionaljTextField;
    private javax.swing.JComboBox permiteBaixaCartaojComboBox;
    private javax.swing.JComboBox permiteCreditoClientejComboBox;
    private javax.swing.JTextField regimeTributariojTextField;
    private javax.swing.JButton sairjButton;
    private javax.swing.JButton salvarjButton;
    private javax.swing.JComboBox situacaojComboBox;
    // End of variables declaration//GEN-END:variables

}
